<%@page import="com.xnx3.j2ee.Global"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>  
<jsp:include page="/wm/common/head.jsp">
	<jsp:param name="title" value="编辑"/>
</jsp:include>
<script src="/js/jquery-1.8.3.min.js" type="text/javascript" charset="utf-8"></script>
<script src="/js/area.js" type="text/javascript"></script>
<script src="/js/selectMore.js" type="text/javascript"></script>
<form class="layui-form" style="padding-top:35px; margin-bottom: 10px; padding-right:35px;">
	<input type="hidden" name="id" value="${entity.id }" />

	<div class="layui-form-item">
		<label class="layui-form-label">代理商名称</label>
		<div class="layui-input-block">
			<input type="text" name="name" class="layui-input"
				value="${entity.name }">
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-form-item">
			<label class="layui-form-label">请选择地区</label>
			<div style="width: 140px;" class="layui-inline">
				<select  name="province" class="province" id="province"
					lay-verify="required" lay-search lay-filter="province">
					<option value="">${entity.addminArea.split(',')[0] }</option>
				</select>
			</div>
			<div style="width: 140px;" class="layui-inline">
				<select name="city" class="city" id="city" lay-verify="required"
					lay-search lay-filter="city">
					<option value="">${entity.addminArea.split(',')[1] }</option>
				</select>
			</div>
			<div style="width: 130px;" class="layui-inline">
				<select name="district" class="district" id="district"
					lay-verify="required" lay-search>
					<option value="">${entity.addminArea.split(',')[2] }</option>
				</select>
			</div>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">负责人</label>
		<div class="layui-input-block">
			<input type="text" name="contactName" class="layui-input" value="${entity.contactName }">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">手机号</label>
		<div class="layui-input-block">
			<input type="text" name="phone" class="layui-input" value="${entity.phone }">
		</div>
	</div>
	
	<div class="layui-form-item">
		<label class="layui-form-label">邮箱</label>
		<div class="layui-input-block">
			<input type="text" name="email" class="layui-input" value="${entity.email }">
		</div>
	</div>
   	<div class="layui-form-item" style="padding-top:15px;">
		<div class="layui-input-block">
			<button class="layui-btn" lay-submit="" lay-filter="demo1">保存</button>
		</div>
	</div>
</form>

<script src="/js/jquery-1.8.3.min.js" type="text/javascript" charset="utf-8"></script>
<script src="/js/area.js" type="text/javascript"></script>
<!-- <script src="/js/selectMore.js" type="text/javascript"></script> -->
<script>
//自适应弹出层大小
var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
//parent.layer.iframeAuto(index);

layui.use(['form', 'layedit', 'laydate', 'element'], function(){
	var form = layui.form,
		element = layui.element;

	//监听提交
	form.on('submit(demo1)', function(data){
		parent.parent.msg.loading("保存中");
		var postDate = wm.getJsonObjectByForm($("form"));	//提交的表单数据
		wm.post('save.json', postDate, function (obj) { 
			parent.parent.msg.close();
			if(obj.result == '1'){
				parent.parent.msg.success("操作成功")
				parent.layer.close(index);
				parent.location.reload();	//刷新父窗口
			}else if(obj.result == '0'){
				parent.parent.msg.failure(obj.info);
			}else{
				parent.parent.msg.failure(result);
			}
		});
	    
		return false;
	});
	
	
	
	
	/**
	 * 三级联动 start
	 */
	var province = $(".province");

	//初始将省份数据赋予
	for (var i = 0; i < provinceList.length; i++) {
		addEle(province, provinceList[i].name);
	}

	//向select中 追加内容
	function addEle(ele, value) {
		var optionStr = "";
		optionStr = "<option value=" + value + " >" + value + "</option>";
		ele.append(optionStr);
	}

	//重新渲染select
	form.render('select');

	//移除select中所有项
	function removeEle(ele) {
		ele.find("option").remove();
		var optionStar = "<option value=''>" + "请选择" + "</option>";
		ele.append(optionStar);
	}

	var provinceText,
		cityText,
		cityItem;
	//选定省份后 将该省份的数据读取追加上	
	form.on('select(province)', function(data) {
		var city = $(data.elem).parents(".layui-form-item").find(".city"),
			district = $(data.elem).parents(".layui-form-item").find(".district");
		provinceText = data.value;
		$.each(provinceList, function(i, item) {
			if (provinceText == item.name) {
				cityItem = i;
				return cityItem;
			}
		});
		removeEle(city);
		removeEle(district);
		$.each(provinceList[cityItem].cityList, function(i, item) {
			addEle(city, item.name);
		})
		form.render('select');
	})

	//选定后 将对应的数据读取追加上
	form.on('select(city)', function(data) {
		var district = $(data.elem).parents(".layui-form-item").find(".district");
		cityText = data.value;
		removeEle(district);
		$.each(provinceList, function(i, item) {
			if (provinceText == item.name) {
				cityItem = i;
				return cityItem;
			}
		});
		$.each(provinceList[cityItem].cityList, function(i, item) {
			if (cityText == item.name) {
				for (var n = 0; n < item.areaList.length; n++) {
					addEle(district, item.areaList[n]);
				}
			}
		})
		form.render('select');
	})
	/* 三级联动 end */
	
});
 function renderForm() {
	layui.use('form', function () {
		var form = layui.form; //高版本建议把括号去掉，有的低版本，需要加()
		form.render();
	});
} 



</script>

<jsp:include page="/wm/common/foot.jsp"></jsp:include> 